package com.cskaoyan.demo;

// import com.mysql.jdbc.Driver;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/07/25 17:17
 *
 * @author ciggar
 */
public class FirstJDBC {
    // 协议 + ip + 端口号 + 路径 + 参数
    static String url = "jdbc:mysql://localhost:3306/43th?useSSL=false&characterEncoding=utf8";
    static String username = "root";
    static String password = "123456";


    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        // 1. 注册驱动
        DriverManager.registerDriver(new Driver());

        // 2. 发送用户名密码，建立连接
        Connection connection = DriverManager.getConnection(url, username, password);

        // 3. 创建statement对象
        Statement statement = connection.createStatement();


        // 4. 发送SQL语句,获取返回结果
        int affectedRows = statement.executeUpdate("insert into city values (8001,'秦皇岛',34)");
//        statement.executeQuery();

        // 5. 解析结果集
        System.out.println("affectedRows:" + affectedRows);

        // 6. 断开连接
        statement.close();
        connection.close();


    }
}
